import {Component, OnInit, Input, Output, EventEmitter} from '@angular/core';
import {TodoService} from './todo-main.service';
import {Todo} from '../model/todo-model';

@Component({
    selector: 'app-todo',
    templateUrl: './todo-main.component.html',
    styleUrls: ['./todo-main.component.css']
})
export class TodoComponent implements OnInit {

    public planContext: string;

    constructor(
        public todoService: TodoService
    ) {
    }

    ngOnInit() {
    }

    public doSubmit(): void {
        this.todoService.save(this.planContext);
        this.todoService.change.emit(true);
        this.planContext = '';
    }

    public doCompleted(todo: Todo): void {
        console.log('===========1');
        this.todoService.pushToCompleted(todo);
        this.todoService.change.emit(true);
        this.todoService.change.emit(false);
        console.log('===========2');
    }

    public doUnCompleted(todo: Todo): void {
        this.todoService.pushToUnCompleted(todo);
        this.todoService.change.emit(true);
        this.todoService.change.emit(false);
    }
}
